package com.example.shushiyunsst.fragment.main.home.child.miner22.mother_icon.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.example.library_common.glidmodule.GlideApp
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.home.child.bean.MotherIconBannerListBean
import com.example.shushiyunsst.fragment.main.home.recycler.bean.BannerEntity
import com.youth.banner.adapter.BannerAdapter

class MotherIconBannerAdapter(data: MutableList<MotherIconBannerListBean>?, context: Context) :
    BannerAdapter<MotherIconBannerListBean, MotherIconBannerAdapter.BannerImgViewHolder>(data) {

    private var layoutInflater: LayoutInflater? = null

    private var mContext: Context = context

    init {
        layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
    }

    override fun onCreateHolder(
        parent: ViewGroup?,
        viewType: Int
    ): BannerImgViewHolder {
        val inflate = layoutInflater
            ?.inflate(R.layout.mother_icon_banner, parent, false) ?: View(mContext)

        inflate.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        return BannerImgViewHolder(inflate)
    }

    class BannerImgViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val imageView: ImageView = view.findViewById(R.id.mBannerImageView)

    }

    override fun onBindView(
        holder: BannerImgViewHolder,
        data: MotherIconBannerListBean?,
        position: Int,
        size: Int
    ) {
        GlideApp.with(mContext)
            .load(data?.modUrl)
            .placeholder(R.drawable.img_erros_bg_rect)
            .into(holder.imageView)
    }

    fun addAll(collection: Collection<MotherIconBannerListBean>?) {
        mDatas.clear()
        if(collection!=null){
            mDatas.addAll(collection)
        }
        notifyDataSetChanged()
    }

}